# Copyright 2021 NXP
# SPDX-License-Identifier: MIT

import SDL
import utime as time
import usys as sys
import lvgl as lv
import lodepng as png
import ustruct

lv.init()
SDL.init(w=240,h=135)

# Register SDL display driver.
disp_buf1 = lv.disp_draw_buf_t()
buf1_1 = bytearray(240*10)
disp_buf1.init(buf1_1, None, len(buf1_1)//4)
disp_drv = lv.disp_drv_t()
disp_drv.init()
disp_drv.draw_buf = disp_buf1
disp_drv.flush_cb = SDL.monitor_flush
disp_drv.hor_res = 240
disp_drv.ver_res = 135
disp_drv.register()

# Regsiter SDL mouse driver
indev_drv = lv.indev_drv_t()
indev_drv.init() 
indev_drv.type = lv.INDEV_TYPE.POINTER
indev_drv.read_cb = SDL.mouse_read
indev_drv.register()

# Below: Taken from https://github.com/lvgl/lv_binding_micropython/blob/master/driver/js/imagetools.py#L22-L94

COLOR_SIZE = lv.color_t.__SIZE__
COLOR_IS_SWAPPED = hasattr(lv.color_t().ch,'green_h')

class lodepng_error(RuntimeError):
    def __init__(self, err):
        if type(err) is int:
            super().__init__(png.error_text(err))
        else:
            super().__init__(err)

# Parse PNG file header
# Taken from https://github.com/shibukawa/imagesize_py/blob/ffef30c1a4715c5acf90e8945ceb77f4a2ed2d45/imagesize.py#L63-L85

def get_png_info(decoder, src, header):
    # Only handle variable image types

    if lv.img.src_get_type(src) != lv.img.SRC.VARIABLE:
        return lv.RES.INV

    data = lv.img_dsc_t.__cast__(src).data
    if data == None:
        return lv.RES.INV

    png_header = bytes(data.__dereference__(24))

    if png_header.startswith(b'\211PNG\r\n\032\n'):
        if png_header[12:16] == b'IHDR':
            start = 16
        # Maybe this is for an older PNG version.
        else:
            start = 8
        try:
            width, height = ustruct.unpack(">LL", png_header[start:start+8])
        except ustruct.error:
            return lv.RES.INV
    else:
        return lv.RES.INV

    header.always_zero = 0
    header.w = width
    header.h = height
    header.cf = lv.img.CF.TRUE_COLOR_ALPHA

    return lv.RES.OK

def convert_rgba8888_to_bgra8888(img_view):
    for i in range(0, len(img_view), lv.color_t.__SIZE__):
        ch = lv.color_t.__cast__(img_view[i:i]).ch
        ch.red, ch.blue = ch.blue, ch.red

# Read and parse PNG file

def open_png(decoder, dsc):
    img_dsc = lv.img_dsc_t.__cast__(dsc.src)
    png_data = img_dsc.data
    png_size = img_dsc.data_size
    png_decoded = png.C_Pointer()
    png_width = png.C_Pointer()
    png_height = png.C_Pointer()
    error = png.decode32(png_decoded, png_width, png_height, png_data, png_size)
    if error:
        raise lodepng_error(error)
    img_size = png_width.int_val * png_height.int_val * 4
    img_data = png_decoded.ptr_val
    img_view = img_data.__dereference__(img_size)

    if COLOR_SIZE == 4:
        convert_rgba8888_to_bgra8888(img_view)
    else:
        raise lodepng_error("Error: Color mode not supported yet!")

    dsc.img_data = img_data
    return lv.RES.OK

# Above: Taken from https://github.com/lvgl/lv_binding_micropython/blob/master/driver/js/imagetools.py#L22-L94

decoder = lv.img.decoder_create()
decoder.info_cb = get_png_info
decoder.open_cb = open_png

def anim_x_cb(obj, v):
    obj.set_x(v)

def anim_y_cb(obj, v):
    obj.set_y(v)

def ta_event_cb(e,kb):
    code = e.get_code()
    ta = e.get_target()
    if code == lv.EVENT.FOCUSED:
        kb.set_textarea(ta)
        kb.clear_flag(lv.obj.FLAG.HIDDEN)

    if code == lv.EVENT.DEFOCUSED:
        kb.set_textarea(None)
        kb.add_flag(lv.obj.FLAG.HIDDEN)


mian = lv.obj()
# create style style_mian_main_main_default
style_mian_main_main_default = lv.style_t()
style_mian_main_main_default.init()
style_mian_main_main_default.set_bg_color(lv.color_make(0xff,0xff,0xff))
style_mian_main_main_default.set_bg_opa(0)

# add style for mian
mian.add_style(style_mian_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian_img_1 = lv.img(mian)
mian_img_1.set_pos(221,0)
mian_img_1.set_size(18,18)
mian_img_1.add_flag(lv.obj.FLAG.CLICKABLE)
try:
    with open('D:\\Users\\Ke\\Desktop\\keya\\generated\\mp-658433665.png','rb') as f:
        mian_img_1_img_data = f.read()
except:
    print('Could not open D:\\Users\\Ke\\Desktop\\keya\\generated\\mp-658433665.png')
    sys.exit()

mian_img_1_img = lv.img_dsc_t({
  'data_size': len(mian_img_1_img_data),
  'header': {'always_zero': 0, 'w': 18, 'h': 18, 'cf': lv.img.CF.TRUE_COLOR_ALPHA},
  'data': mian_img_1_img_data
})

mian_img_1.set_src(mian_img_1_img)
mian_img_1.set_pivot(0,0)
mian_img_1.set_angle(0)
# create style style_mian_img_1_main_main_default
style_mian_img_1_main_main_default = lv.style_t()
style_mian_img_1_main_main_default.init()
style_mian_img_1_main_main_default.set_img_recolor(lv.color_make(0xff,0xff,0xff))
style_mian_img_1_main_main_default.set_img_recolor_opa(0)
style_mian_img_1_main_main_default.set_img_opa(255)

# add style for mian_img_1
mian_img_1.add_style(style_mian_img_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian_Electricity = lv.label(mian)
mian_Electricity.set_pos(206,5)
mian_Electricity.set_size(15,10)
mian_Electricity.set_text("15%")
mian_Electricity.set_long_mode(lv.label.LONG.WRAP)
mian_Electricity.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian_electricity_main_main_default
style_mian_electricity_main_main_default = lv.style_t()
style_mian_electricity_main_main_default.init()
style_mian_electricity_main_main_default.set_radius(0)
style_mian_electricity_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian_electricity_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian_electricity_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian_electricity_main_main_default.set_bg_opa(0)
style_mian_electricity_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian_electricity_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian_electricity_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian_electricity_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian_electricity_main_main_default.set_text_letter_space(0)
style_mian_electricity_main_main_default.set_pad_left(0)
style_mian_electricity_main_main_default.set_pad_right(0)
style_mian_electricity_main_main_default.set_pad_top(0)
style_mian_electricity_main_main_default.set_pad_bottom(0)

# add style for mian_Electricity
mian_Electricity.add_style(style_mian_electricity_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian_date = lv.label(mian)
mian_date.set_pos(26,5)
mian_date.set_size(44,10)
mian_date.set_text("2024/04/11")
mian_date.set_long_mode(lv.label.LONG.WRAP)
mian_date.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian_date_main_main_default
style_mian_date_main_main_default = lv.style_t()
style_mian_date_main_main_default.init()
style_mian_date_main_main_default.set_radius(0)
style_mian_date_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian_date_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian_date_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian_date_main_main_default.set_bg_opa(0)
style_mian_date_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian_date_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian_date_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian_date_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian_date_main_main_default.set_text_letter_space(0)
style_mian_date_main_main_default.set_pad_left(0)
style_mian_date_main_main_default.set_pad_right(0)
style_mian_date_main_main_default.set_pad_top(0)
style_mian_date_main_main_default.set_pad_bottom(0)

# add style for mian_date
mian_date.add_style(style_mian_date_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian_label_1 = lv.label(mian)
mian_label_1.set_pos(70,5)
mian_label_1.set_size(30,10)
mian_label_1.set_text("11:10")
mian_label_1.set_long_mode(lv.label.LONG.WRAP)
mian_label_1.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian_label_1_main_main_default
style_mian_label_1_main_main_default = lv.style_t()
style_mian_label_1_main_main_default.init()
style_mian_label_1_main_main_default.set_radius(0)
style_mian_label_1_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian_label_1_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian_label_1_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian_label_1_main_main_default.set_bg_opa(0)
style_mian_label_1_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian_label_1_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian_label_1_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian_label_1_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian_label_1_main_main_default.set_text_letter_space(2)
style_mian_label_1_main_main_default.set_pad_left(0)
style_mian_label_1_main_main_default.set_pad_right(0)
style_mian_label_1_main_main_default.set_pad_top(0)
style_mian_label_1_main_main_default.set_pad_bottom(0)

# add style for mian_label_1
mian_label_1.add_style(style_mian_label_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian_label_2 = lv.label(mian)
mian_label_2.set_pos(62,52)
mian_label_2.set_size(100,27)
mian_label_2.set_text("1")
mian_label_2.set_long_mode(lv.label.LONG.WRAP)
mian_label_2.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
# create style style_mian_label_2_main_main_default
style_mian_label_2_main_main_default = lv.style_t()
style_mian_label_2_main_main_default.init()
style_mian_label_2_main_main_default.set_radius(0)
style_mian_label_2_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian_label_2_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian_label_2_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian_label_2_main_main_default.set_bg_opa(255)
style_mian_label_2_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian_label_2_main_main_default.set_text_font(lv.font_montserratMedium_12)
except AttributeError:
    try:
        style_mian_label_2_main_main_default.set_text_font(lv.font_montserrat_12)
    except AttributeError:
        style_mian_label_2_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian_label_2_main_main_default.set_text_letter_space(2)
style_mian_label_2_main_main_default.set_pad_left(0)
style_mian_label_2_main_main_default.set_pad_right(0)
style_mian_label_2_main_main_default.set_pad_top(0)
style_mian_label_2_main_main_default.set_pad_bottom(0)

# add style for mian_label_2
mian_label_2.add_style(style_mian_label_2_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian_btn_1 = lv.btn(mian)
mian_btn_1.set_pos(139,85)
mian_btn_1.set_size(100,50)
mian_btn_1_label = lv.label(mian_btn_1)
mian_btn_1_label.set_text("default")
mian_btn_1.set_style_pad_all(0, lv.STATE.DEFAULT)
mian_btn_1_label.align(lv.ALIGN.CENTER,0,0)
mian_btn_1_label.set_style_text_color(lv.color_make(0x00,0x00,0x00), lv.STATE.DEFAULT)
try:
    mian_btn_1_label.set_style_text_font(lv.font_simsun_12, lv.STATE.DEFAULT)
except AttributeError:
    try:
        mian_btn_1_label.set_style_text_font(lv.font_montserrat_12, lv.STATE.DEFAULT)
    except AttributeError:
        mian_btn_1_label.set_style_text_font(lv.font_montserrat_16, lv.STATE.DEFAULT)
# create style style_mian_btn_1_main_main_default
style_mian_btn_1_main_main_default = lv.style_t()
style_mian_btn_1_main_main_default.init()
style_mian_btn_1_main_main_default.set_radius(5)
style_mian_btn_1_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian_btn_1_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian_btn_1_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian_btn_1_main_main_default.set_bg_opa(255)
style_mian_btn_1_main_main_default.set_shadow_color(lv.color_make(0x21,0x95,0xf6))
style_mian_btn_1_main_main_default.set_shadow_opa(255)
style_mian_btn_1_main_main_default.set_border_color(lv.color_make(0x21,0x95,0xf6))
style_mian_btn_1_main_main_default.set_border_width(0)
style_mian_btn_1_main_main_default.set_border_opa(255)

# add style for mian_btn_1
mian_btn_1.add_style(style_mian_btn_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1 = lv.obj()
# create style style_mian1_main_main_default
style_mian1_main_main_default = lv.style_t()
style_mian1_main_main_default.init()
style_mian1_main_main_default.set_bg_color(lv.color_make(0xff,0xff,0xff))
style_mian1_main_main_default.set_bg_opa(0)

# add style for mian1
mian1.add_style(style_mian1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1_img_1 = lv.img(mian1)
mian1_img_1.set_pos(221,0)
mian1_img_1.set_size(18,18)
mian1_img_1.add_flag(lv.obj.FLAG.CLICKABLE)
try:
    with open('D:\\Users\\Ke\\Desktop\\keya\\generated\\mp-658433665.png','rb') as f:
        mian1_img_1_img_data = f.read()
except:
    print('Could not open D:\\Users\\Ke\\Desktop\\keya\\generated\\mp-658433665.png')
    sys.exit()

mian1_img_1_img = lv.img_dsc_t({
  'data_size': len(mian1_img_1_img_data),
  'header': {'always_zero': 0, 'w': 18, 'h': 18, 'cf': lv.img.CF.TRUE_COLOR_ALPHA},
  'data': mian1_img_1_img_data
})

mian1_img_1.set_src(mian1_img_1_img)
mian1_img_1.set_pivot(0,0)
mian1_img_1.set_angle(0)
# create style style_mian1_img_1_main_main_default
style_mian1_img_1_main_main_default = lv.style_t()
style_mian1_img_1_main_main_default.init()
style_mian1_img_1_main_main_default.set_img_recolor(lv.color_make(0xff,0xff,0xff))
style_mian1_img_1_main_main_default.set_img_recolor_opa(0)
style_mian1_img_1_main_main_default.set_img_opa(255)

# add style for mian1_img_1
mian1_img_1.add_style(style_mian1_img_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1_Electricity = lv.label(mian1)
mian1_Electricity.set_pos(206,5)
mian1_Electricity.set_size(15,10)
mian1_Electricity.set_text("15%")
mian1_Electricity.set_long_mode(lv.label.LONG.WRAP)
mian1_Electricity.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian1_electricity_main_main_default
style_mian1_electricity_main_main_default = lv.style_t()
style_mian1_electricity_main_main_default.init()
style_mian1_electricity_main_main_default.set_radius(0)
style_mian1_electricity_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_electricity_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_electricity_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian1_electricity_main_main_default.set_bg_opa(0)
style_mian1_electricity_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian1_electricity_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian1_electricity_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian1_electricity_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian1_electricity_main_main_default.set_text_letter_space(0)
style_mian1_electricity_main_main_default.set_pad_left(0)
style_mian1_electricity_main_main_default.set_pad_right(0)
style_mian1_electricity_main_main_default.set_pad_top(0)
style_mian1_electricity_main_main_default.set_pad_bottom(0)

# add style for mian1_Electricity
mian1_Electricity.add_style(style_mian1_electricity_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1_date = lv.label(mian1)
mian1_date.set_pos(26,5)
mian1_date.set_size(44,10)
mian1_date.set_text("2024/04/11")
mian1_date.set_long_mode(lv.label.LONG.WRAP)
mian1_date.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian1_date_main_main_default
style_mian1_date_main_main_default = lv.style_t()
style_mian1_date_main_main_default.init()
style_mian1_date_main_main_default.set_radius(0)
style_mian1_date_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_date_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_date_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian1_date_main_main_default.set_bg_opa(0)
style_mian1_date_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian1_date_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian1_date_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian1_date_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian1_date_main_main_default.set_text_letter_space(0)
style_mian1_date_main_main_default.set_pad_left(0)
style_mian1_date_main_main_default.set_pad_right(0)
style_mian1_date_main_main_default.set_pad_top(0)
style_mian1_date_main_main_default.set_pad_bottom(0)

# add style for mian1_date
mian1_date.add_style(style_mian1_date_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1_label_1 = lv.label(mian1)
mian1_label_1.set_pos(70,5)
mian1_label_1.set_size(30,10)
mian1_label_1.set_text("11:10")
mian1_label_1.set_long_mode(lv.label.LONG.WRAP)
mian1_label_1.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian1_label_1_main_main_default
style_mian1_label_1_main_main_default = lv.style_t()
style_mian1_label_1_main_main_default.init()
style_mian1_label_1_main_main_default.set_radius(0)
style_mian1_label_1_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_label_1_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_label_1_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian1_label_1_main_main_default.set_bg_opa(0)
style_mian1_label_1_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian1_label_1_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian1_label_1_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian1_label_1_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian1_label_1_main_main_default.set_text_letter_space(2)
style_mian1_label_1_main_main_default.set_pad_left(0)
style_mian1_label_1_main_main_default.set_pad_right(0)
style_mian1_label_1_main_main_default.set_pad_top(0)
style_mian1_label_1_main_main_default.set_pad_bottom(0)

# add style for mian1_label_1
mian1_label_1.add_style(style_mian1_label_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1_label_3 = lv.label(mian1)
mian1_label_3.set_pos(70,57)
mian1_label_3.set_size(100,27)
mian1_label_3.set_text("2")
mian1_label_3.set_long_mode(lv.label.LONG.WRAP)
mian1_label_3.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
# create style style_mian1_label_3_main_main_default
style_mian1_label_3_main_main_default = lv.style_t()
style_mian1_label_3_main_main_default.init()
style_mian1_label_3_main_main_default.set_radius(0)
style_mian1_label_3_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_label_3_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_label_3_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian1_label_3_main_main_default.set_bg_opa(255)
style_mian1_label_3_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian1_label_3_main_main_default.set_text_font(lv.font_montserratMedium_12)
except AttributeError:
    try:
        style_mian1_label_3_main_main_default.set_text_font(lv.font_montserrat_12)
    except AttributeError:
        style_mian1_label_3_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian1_label_3_main_main_default.set_text_letter_space(2)
style_mian1_label_3_main_main_default.set_pad_left(0)
style_mian1_label_3_main_main_default.set_pad_right(0)
style_mian1_label_3_main_main_default.set_pad_top(0)
style_mian1_label_3_main_main_default.set_pad_bottom(0)

# add style for mian1_label_3
mian1_label_3.add_style(style_mian1_label_3_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian1_btn_2 = lv.btn(mian1)
mian1_btn_2.set_pos(140,85)
mian1_btn_2.set_size(100,50)
mian1_btn_2_label = lv.label(mian1_btn_2)
mian1_btn_2_label.set_text("default")
mian1_btn_2.set_style_pad_all(0, lv.STATE.DEFAULT)
mian1_btn_2_label.align(lv.ALIGN.CENTER,0,0)
mian1_btn_2_label.set_style_text_color(lv.color_make(0x00,0x00,0x00), lv.STATE.DEFAULT)
try:
    mian1_btn_2_label.set_style_text_font(lv.font_simsun_12, lv.STATE.DEFAULT)
except AttributeError:
    try:
        mian1_btn_2_label.set_style_text_font(lv.font_montserrat_12, lv.STATE.DEFAULT)
    except AttributeError:
        mian1_btn_2_label.set_style_text_font(lv.font_montserrat_16, lv.STATE.DEFAULT)
# create style style_mian1_btn_2_main_main_default
style_mian1_btn_2_main_main_default = lv.style_t()
style_mian1_btn_2_main_main_default.init()
style_mian1_btn_2_main_main_default.set_radius(5)
style_mian1_btn_2_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_btn_2_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_btn_2_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian1_btn_2_main_main_default.set_bg_opa(255)
style_mian1_btn_2_main_main_default.set_shadow_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_btn_2_main_main_default.set_shadow_opa(255)
style_mian1_btn_2_main_main_default.set_border_color(lv.color_make(0x21,0x95,0xf6))
style_mian1_btn_2_main_main_default.set_border_width(0)
style_mian1_btn_2_main_main_default.set_border_opa(255)

# add style for mian1_btn_2
mian1_btn_2.add_style(style_mian1_btn_2_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2 = lv.obj()
# create style style_mian2_main_main_default
style_mian2_main_main_default = lv.style_t()
style_mian2_main_main_default.init()
style_mian2_main_main_default.set_bg_color(lv.color_make(0xff,0xff,0xff))
style_mian2_main_main_default.set_bg_opa(0)

# add style for mian2
mian2.add_style(style_mian2_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2_img_1 = lv.img(mian2)
mian2_img_1.set_pos(221,0)
mian2_img_1.set_size(18,18)
mian2_img_1.add_flag(lv.obj.FLAG.CLICKABLE)
try:
    with open('D:\\Users\\Ke\\Desktop\\keya\\generated\\mp-658433665.png','rb') as f:
        mian2_img_1_img_data = f.read()
except:
    print('Could not open D:\\Users\\Ke\\Desktop\\keya\\generated\\mp-658433665.png')
    sys.exit()

mian2_img_1_img = lv.img_dsc_t({
  'data_size': len(mian2_img_1_img_data),
  'header': {'always_zero': 0, 'w': 18, 'h': 18, 'cf': lv.img.CF.TRUE_COLOR_ALPHA},
  'data': mian2_img_1_img_data
})

mian2_img_1.set_src(mian2_img_1_img)
mian2_img_1.set_pivot(0,0)
mian2_img_1.set_angle(0)
# create style style_mian2_img_1_main_main_default
style_mian2_img_1_main_main_default = lv.style_t()
style_mian2_img_1_main_main_default.init()
style_mian2_img_1_main_main_default.set_img_recolor(lv.color_make(0xff,0xff,0xff))
style_mian2_img_1_main_main_default.set_img_recolor_opa(0)
style_mian2_img_1_main_main_default.set_img_opa(255)

# add style for mian2_img_1
mian2_img_1.add_style(style_mian2_img_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2_Electricity = lv.label(mian2)
mian2_Electricity.set_pos(206,5)
mian2_Electricity.set_size(15,10)
mian2_Electricity.set_text("15%")
mian2_Electricity.set_long_mode(lv.label.LONG.WRAP)
mian2_Electricity.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian2_electricity_main_main_default
style_mian2_electricity_main_main_default = lv.style_t()
style_mian2_electricity_main_main_default.init()
style_mian2_electricity_main_main_default.set_radius(0)
style_mian2_electricity_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_electricity_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_electricity_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian2_electricity_main_main_default.set_bg_opa(0)
style_mian2_electricity_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian2_electricity_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian2_electricity_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian2_electricity_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian2_electricity_main_main_default.set_text_letter_space(0)
style_mian2_electricity_main_main_default.set_pad_left(0)
style_mian2_electricity_main_main_default.set_pad_right(0)
style_mian2_electricity_main_main_default.set_pad_top(0)
style_mian2_electricity_main_main_default.set_pad_bottom(0)

# add style for mian2_Electricity
mian2_Electricity.add_style(style_mian2_electricity_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2_date = lv.label(mian2)
mian2_date.set_pos(26,5)
mian2_date.set_size(44,10)
mian2_date.set_text("2024/04/11")
mian2_date.set_long_mode(lv.label.LONG.WRAP)
mian2_date.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian2_date_main_main_default
style_mian2_date_main_main_default = lv.style_t()
style_mian2_date_main_main_default.init()
style_mian2_date_main_main_default.set_radius(0)
style_mian2_date_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_date_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_date_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian2_date_main_main_default.set_bg_opa(0)
style_mian2_date_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian2_date_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian2_date_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian2_date_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian2_date_main_main_default.set_text_letter_space(0)
style_mian2_date_main_main_default.set_pad_left(0)
style_mian2_date_main_main_default.set_pad_right(0)
style_mian2_date_main_main_default.set_pad_top(0)
style_mian2_date_main_main_default.set_pad_bottom(0)

# add style for mian2_date
mian2_date.add_style(style_mian2_date_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2_label_1 = lv.label(mian2)
mian2_label_1.set_pos(70,5)
mian2_label_1.set_size(30,10)
mian2_label_1.set_text("11:10")
mian2_label_1.set_long_mode(lv.label.LONG.WRAP)
mian2_label_1.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
# create style style_mian2_label_1_main_main_default
style_mian2_label_1_main_main_default = lv.style_t()
style_mian2_label_1_main_main_default.init()
style_mian2_label_1_main_main_default.set_radius(0)
style_mian2_label_1_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_label_1_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_label_1_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian2_label_1_main_main_default.set_bg_opa(0)
style_mian2_label_1_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian2_label_1_main_main_default.set_text_font(lv.font_montserratMedium_7)
except AttributeError:
    try:
        style_mian2_label_1_main_main_default.set_text_font(lv.font_montserrat_7)
    except AttributeError:
        style_mian2_label_1_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian2_label_1_main_main_default.set_text_letter_space(2)
style_mian2_label_1_main_main_default.set_pad_left(0)
style_mian2_label_1_main_main_default.set_pad_right(0)
style_mian2_label_1_main_main_default.set_pad_top(0)
style_mian2_label_1_main_main_default.set_pad_bottom(0)

# add style for mian2_label_1
mian2_label_1.add_style(style_mian2_label_1_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2_label_3 = lv.label(mian2)
mian2_label_3.set_pos(63,45)
mian2_label_3.set_size(100,27)
mian2_label_3.set_text("3")
mian2_label_3.set_long_mode(lv.label.LONG.WRAP)
mian2_label_3.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
# create style style_mian2_label_3_main_main_default
style_mian2_label_3_main_main_default = lv.style_t()
style_mian2_label_3_main_main_default.init()
style_mian2_label_3_main_main_default.set_radius(0)
style_mian2_label_3_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_label_3_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_label_3_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian2_label_3_main_main_default.set_bg_opa(255)
style_mian2_label_3_main_main_default.set_text_color(lv.color_make(0x00,0x00,0x00))
try:
    style_mian2_label_3_main_main_default.set_text_font(lv.font_montserratMedium_12)
except AttributeError:
    try:
        style_mian2_label_3_main_main_default.set_text_font(lv.font_montserrat_12)
    except AttributeError:
        style_mian2_label_3_main_main_default.set_text_font(lv.font_montserrat_16)
style_mian2_label_3_main_main_default.set_text_letter_space(2)
style_mian2_label_3_main_main_default.set_pad_left(0)
style_mian2_label_3_main_main_default.set_pad_right(0)
style_mian2_label_3_main_main_default.set_pad_top(0)
style_mian2_label_3_main_main_default.set_pad_bottom(0)

# add style for mian2_label_3
mian2_label_3.add_style(style_mian2_label_3_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)

mian2_btn_2 = lv.btn(mian2)
mian2_btn_2.set_pos(140,84)
mian2_btn_2.set_size(100,50)
mian2_btn_2_label = lv.label(mian2_btn_2)
mian2_btn_2_label.set_text("default")
mian2_btn_2.set_style_pad_all(0, lv.STATE.DEFAULT)
mian2_btn_2_label.align(lv.ALIGN.CENTER,0,0)
mian2_btn_2_label.set_style_text_color(lv.color_make(0x00,0x00,0x00), lv.STATE.DEFAULT)
try:
    mian2_btn_2_label.set_style_text_font(lv.font_simsun_12, lv.STATE.DEFAULT)
except AttributeError:
    try:
        mian2_btn_2_label.set_style_text_font(lv.font_montserrat_12, lv.STATE.DEFAULT)
    except AttributeError:
        mian2_btn_2_label.set_style_text_font(lv.font_montserrat_16, lv.STATE.DEFAULT)
# create style style_mian2_btn_2_main_main_default
style_mian2_btn_2_main_main_default = lv.style_t()
style_mian2_btn_2_main_main_default.init()
style_mian2_btn_2_main_main_default.set_radius(5)
style_mian2_btn_2_main_main_default.set_bg_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_btn_2_main_main_default.set_bg_grad_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_btn_2_main_main_default.set_bg_grad_dir(lv.GRAD_DIR.VER)
style_mian2_btn_2_main_main_default.set_bg_opa(255)
style_mian2_btn_2_main_main_default.set_shadow_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_btn_2_main_main_default.set_shadow_opa(255)
style_mian2_btn_2_main_main_default.set_border_color(lv.color_make(0x21,0x95,0xf6))
style_mian2_btn_2_main_main_default.set_border_width(0)
style_mian2_btn_2_main_main_default.set_border_opa(255)

# add style for mian2_btn_2
mian2_btn_2.add_style(style_mian2_btn_2_main_main_default, lv.PART.MAIN|lv.STATE.DEFAULT)



def mian_btn_1_clicked_1_event_cb(e,mian1):
    src = e.get_target()
    code = e.get_code()
    lv.scr_load_anim(mian1, lv.SCR_LOAD_ANIM.OVER_LEFT, 0, 0, False)
mian_btn_1.add_event_cb(lambda e: mian_btn_1_clicked_1_event_cb(e,mian1), lv.EVENT.CLICKED, None)


def mian2_btn_2_clicked_1_event_cb(e,mian):
    src = e.get_target()
    code = e.get_code()
    lv.scr_load_anim(mian, lv.SCR_LOAD_ANIM.OVER_LEFT, 0, 0, False)
mian2_btn_2.add_event_cb(lambda e: mian2_btn_2_clicked_1_event_cb(e,mian), lv.EVENT.CLICKED, None)


def mian1_btn_2_clicked_1_event_cb(e,mian2):
    src = e.get_target()
    code = e.get_code()
    lv.scr_load_anim(mian2, lv.SCR_LOAD_ANIM.OVER_LEFT, 0, 0, False)
mian1_btn_2.add_event_cb(lambda e: mian1_btn_2_clicked_1_event_cb(e,mian2), lv.EVENT.CLICKED, None)



# content from custom.py

# Load the default screen
lv.scr_load(mian)

while SDL.check():
    time.sleep_ms(5)
